<template>
  <div>
    <h2>取款页面</h2>
    <div>
      账号姓名：<el-input v-model="water.name" style="width: 300px" disabled></el-input><br>
      账号号码：<el-input v-model="water.number" style="width: 300px" disabled></el-input><br>
      账号余额：<el-input v-model="water.balance" style="width: 300px" disabled></el-input><br>
      开户时间：<el-input v-model="water.beginTime" style="width: 300px" disabled></el-input><br>
      取款金额：<el-input v-model="water.moneyUser" style="width: 300px"></el-input><br>
      <el-button @click="take">取款</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TakeView',
  data () {
    return {
      water: {
        id: null,
        name: '',
        number: '',
        balance: null,
        beginTime: '',
        moneyUser: null,
        moneyEnd: null,
        type: '',
        nowTime: '',
        acid: null
      },
      account: {
        id: null,
        name: '',
        number: '',
        balance: null,
        beginTime: '',
        moneyUser: null
      }
    }
  },
  methods: {
    // 取款
    take () {
      this.axios.post('/water/takeWater', this.water)
        .then(res => {
          if (res.data.code === 200) {
            this.$message.success('取款成功')
            this.update()
            this.$router.push('/stream')
          } if (res.data.code === 201) {
            this.$message.error('余额不足')
          } if (res.data.code === 400) {
            this.$message.error('取款失败')
          }
        })
    },
    update () {
      this.axios.post('/account/updateAc2', this.account)
        .then(res => {
          console.log(res.data)
        })
    }
  },
  // 回显 回显账号信息
  created () {
    this.axios.get('/account/getAccount', { params: { id: this.$route.query.id } })
      .then(res => {
        this.water = res.data.jdata
        this.account = res.data.jdata
        this.water.acid = res.data.jdata.id
        this.account.id = this.water.acid
      })
  }
}
</script>

<style scoped>

</style>
